from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-02-11 14:07:13.548085
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 11, Feb, 2022
Time: 14:07:18
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.0708
Nobs: 564.000 HQIC: -48.4926
Log likelihood: 6638.52 FPE: 6.64805e-22
AIC: -48.7626 Det(Omega_mle): 5.67544e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.349651 0.068909 5.074 0.000
L1.Burgenland 0.106427 0.041921 2.539 0.011
L1.Kärnten -0.110785 0.021778 -5.087 0.000
L1.Niederösterreich 0.195067 0.087530 2.229 0.026
L1.Oberösterreich 0.129654 0.086402 1.501 0.133
L1.Salzburg 0.254743 0.044319 5.748 0.000
L1.Steiermark 0.035454 0.058435 0.607 0.544
L1.Tirol 0.099618 0.047155 2.113 0.035
L1.Vorarlberg -0.071792 0.041665 -1.723 0.085
L1.Wien 0.019260 0.076792 0.251 0.802
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056657 0.149120 0.380 0.704
L1.Burgenland -0.040856 0.090717 -0.450 0.652
L1.Kärnten 0.041242 0.047129 0.875 0.382
L1.Niederösterreich -0.199186 0.189417 -1.052 0.293
L1.Oberösterreich 0.459741 0.186976 2.459 0.014
L1.Salzburg 0.281862 0.095907 2.939 0.003
L1.Steiermark 0.113069 0.126453 0.894 0.371
L1.Tirol 0.304046 0.102043 2.980 0.003
L1.Vorarlberg 0.022906 0.090163 0.254 0.799
L1.Wien -0.029588 0.166178 -0.178 0.859
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.196727 0.035152 5.596 0.000
L1.Burgenland 0.090567 0.021385 4.235 0.000
L1.Kärnten -0.007378 0.011110 -0.664 0.507
L1.Niederösterreich 0.235335 0.044651 5.271 0.000
L1.Oberösterreich 0.165407 0.044076 3.753 0.000
L1.Salzburg 0.039908 0.022608 1.765 0.078
L1.Steiermark 0.026710 0.029809 0.896 0.370
L1.Tirol 0.082418 0.024055 3.426 0.001
L1.Vorarlberg 0.054823 0.021254 2.579 0.010
L1.Wien 0.117220 0.039173 2.992 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.121291 0.035228 3.443 0.001
L1.Burgenland 0.043540 0.021431 2.032 0.042
L1.Kärnten -0.013251 0.011134 -1.190 0.234
L1.Niederösterreich 0.170212 0.044747 3.804 0.000
L1.Oberösterreich 0.335717 0.044171 7.600 0.000
L1.Salzburg 0.099950 0.022657 4.411 0.000
L1.Steiermark 0.110407 0.029873 3.696 0.000
L1.Tirol 0.090324 0.024106 3.747 0.000
L1.Vorarlberg 0.060600 0.021300 2.845 0.004
L1.Wien -0.018914 0.039257 -0.482 0.630
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.125206 0.066321 1.888 0.059
L1.Burgenland -0.048120 0.040346 -1.193 0.233
L1.Kärnten -0.045462 0.020960 -2.169 0.030
L1.Niederösterreich 0.140488 0.084243 1.668 0.095
L1.Oberösterreich 0.163983 0.083157 1.972 0.049
L1.Salzburg 0.284337 0.042655 6.666 0.000
L1.Steiermark 0.057280 0.056240 1.018 0.308
L1.Tirol 0.156081 0.045384 3.439 0.001
L1.Vorarlberg 0.094386 0.040100 2.354 0.019
L1.Wien 0.075036 0.073908 1.015 0.310
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.080611 0.051779 1.557 0.120
L1.Burgenland 0.025259 0.031500 0.802 0.423
L1.Kärnten 0.053224 0.016365 3.252 0.001
L1.Niederösterreich 0.191439 0.065772 2.911 0.004
L1.Oberösterreich 0.328386 0.064924 5.058 0.000
L1.Salzburg 0.033745 0.033302 1.013 0.311
L1.Steiermark 0.005631 0.043909 0.128 0.898
L1.Tirol 0.120511 0.035433 3.401 0.001
L1.Vorarlberg 0.065360 0.031308 2.088 0.037
L1.Wien 0.097712 0.057703 1.693 0.090
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.171146 0.062562 2.736 0.006
L1.Burgenland 0.003712 0.038060 0.098 0.922
L1.Kärnten -0.065966 0.019772 -3.336 0.001
L1.Niederösterreich -0.108775 0.079468 -1.369 0.171
L1.Oberösterreich 0.210750 0.078444 2.687 0.007
L1.Salzburg 0.053515 0.040237 1.330 0.184
L1.Steiermark 0.249193 0.053052 4.697 0.000
L1.Tirol 0.499501 0.042811 11.667 0.000
L1.Vorarlberg 0.064388 0.037827 1.702 0.089
L1.Wien -0.074241 0.069719 -1.065 0.287
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160461 0.069277 2.316 0.021
L1.Burgenland -0.004572 0.042145 -0.108 0.914
L1.Kärnten 0.062293 0.021895 2.845 0.004
L1.Niederösterreich 0.176719 0.087998 2.008 0.045
L1.Oberösterreich -0.062548 0.086864 -0.720 0.471
L1.Salzburg 0.206100 0.044556 4.626 0.000
L1.Steiermark 0.138259 0.058747 2.353 0.019
L1.Tirol 0.056649 0.047407 1.195 0.232
L1.Vorarlberg 0.143378 0.041888 3.423 0.001
L1.Wien 0.126689 0.077202 1.641 0.101
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.393258 0.040631 9.679 0.000
L1.Burgenland -0.002753 0.024718 -0.111 0.911
L1.Kärnten -0.021369 0.012841 -1.664 0.096
L1.Niederösterreich 0.200144 0.051611 3.878 0.000
L1.Oberösterreich 0.230963 0.050946 4.533 0.000
L1.Salzburg 0.036631 0.026132 1.402 0.161
L1.Steiermark -0.017258 0.034455 -0.501 0.616
L1.Tirol 0.091155 0.027804 3.278 0.001
L1.Vorarlberg 0.051145 0.024567 2.082 0.037
L1.Wien 0.041029 0.045279 0.906 0.365
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.035152 0.105475 0.168668 0.134236 0.096209 0.081390 0.029924 0.212518
Kärnten 0.035152 1.000000 -0.025834 0.132503 0.046964 0.085595 0.443920 -0.067993 0.090348
Niederösterreich 0.105475 -0.025834 1.000000 0.312492 0.124329 0.270587 0.066148 0.156442 0.284586
Oberösterreich 0.168668 0.132503 0.312492 1.000000 0.214720 0.293748 0.168165 0.135224 0.235892
Salzburg 0.134236 0.046964 0.124329 0.214720 1.000000 0.124781 0.091395 0.103853 0.127604
Steiermark 0.096209 0.085595 0.270587 0.293748 0.124781 1.000000 0.134930 0.106247 0.032137
Tirol 0.081390 0.443920 0.066148 0.168165 0.091395 0.134930 1.000000 0.063903 0.152885
Vorarlberg 0.029924 -0.067993 0.156442 0.135224 0.103853 0.106247 0.063903 1.000000 -0.003408
Wien 0.212518 0.090348 0.284586 0.235892 0.127604 0.032137 0.152885 -0.003408 1.000000